package com.yongcheon.sms_manager.ui.preference;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.yongcheon.sms_manager.R;
import com.yongcheon.sms_manager.data.preference.SpamSentenceData;
import com.yongcheon.sms_manager.vo.SpamSentenceVO;

/**
 * Created by yongcheon on 2014-12-09.
 */
public class SpamSentenceCursorAdapter extends CursorAdapter {
    LayoutInflater Inflater;
    SpamSentenceData spamSentenceData;

    public void setSpamNumberData(SpamSentenceData spamSentenceData) {
        this.spamSentenceData = spamSentenceData;
    }

    public SpamSentenceCursorAdapter(Context context, Cursor c) {
        super(context, c);
        Inflater = LayoutInflater.from(context);
    }
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        View newView = Inflater.inflate(R.layout.spam_sentence_list_item, parent, false);
        return newView;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        SpamSentenceVO spamentenceVO = spamSentenceData.createSpamSentenceVOFromCursor(cursor);

        TextView sentence = (TextView)view.findViewById(R.id.spam_centence);
        sentence.setText(spamentenceVO.getSentence());

        SpamSentenceLongClickListener longClickListener = new SpamSentenceLongClickListener(view, spamentenceVO, this);
        view.setOnLongClickListener(longClickListener);
    }
}
